package com.crane.common.framework.utils;

import com.crane.common.core.utils.Md5Util;
import com.crane.common.core.utils.StringUtil;

import java.util.Map;
import java.util.TreeMap;

/**
 * @author bealon
 */
public class SignUtil {

    public static String getSign(Object obj,String secret) {
        Map<String, Object> map=BeanUtil.asMap(obj,"sign");
        TreeMap<String, Object> treeMap=new TreeMap(map);
        StringBuilder paras=new StringBuilder();
        for(Map.Entry<String,Object> entry : treeMap.entrySet()){
             if(null != entry.getValue()){
                 paras.append(entry.getKey()).append("=").append(entry.getValue().toString()).append("&");
             }
        }
        return Md5Util.md5EncodeBase64(paras.append("secret").append("=").append(secret).toString());
    }

}
